package com.llc.station.kcp.ui.core.component;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;

/**
 * 作者 zxj<br>
 * 时间 2017/9/13 18:33
 * 说明 ...
 */
public class CarPane extends StackPane {

    protected String carNumber;

    protected String tag;



    public CarPane(String carNumber, String tag, double width, double height) {
        this.carNumber = carNumber;
        this.tag = tag;
        this.setPrefWidth(width);
        this.setPrefHeight(height);
        init();
    }

    public CarPane(String carNumber, String tag, double width, double height, Node... children) {
        super(children);
        this.carNumber = carNumber;
        this.tag = tag;
        this.setPrefWidth(width);
        this.setPrefHeight(height);
        init();
    }

    private void init(){
        this.getStyleClass().add("carPane");
        double height = this.getPrefHeight();
        double width = this.getPrefWidth();
        double piceWidth = height / 2;
        Pane hBoxPane = new Pane();
        HBox hBox = new HBox();
        hBoxPane.getChildren().add(hBox);
        hBox.setAlignment(Pos.CENTER);
        hBox.setPrefWidth(width - piceWidth);
        hBox.setPrefHeight(height - piceWidth / 2);
        hBox.setLayoutX(piceWidth / 2);
        hBox.setLayoutY(piceWidth / 2);


        hBox.getStyleClass().add("carPane-grid");
        Label label = new Label(carNumber);
        hBox.getChildren().add(label);
        label.getStyleClass().add("carPane-carNumber");
        this.getChildren().add(hBoxPane);

        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setPrefWidth(width);
        anchorPane.setPrefHeight(height);
        PiceText piceText = new PiceText(piceWidth);
        piceText.setText(tag);
        AnchorPane.setTopAnchor(piceText,0.0);
        AnchorPane.setRightAnchor(piceText,0.0);
        anchorPane.getChildren().add(piceText);
        this.getChildren().add(anchorPane);



        this.setBorder(new Border(new BorderStroke(Color.rgb(1,1,1), BorderStrokeStyle.DASHED, CornerRadii.EMPTY, BorderStroke.DEFAULT_WIDTHS)));
    }
}
